package com.service.scheduling.support;

import com.service.scheduling.constants.RedisLockConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;

@Slf4j
@Component
public class OrderProductHrComboLockUtils extends RedissonLockUtils{
	public boolean lock(@NotNull String key) {
		return super.lock(buildKey(key));
	}

	public void unlock(@NotNull String key) {
		super.unlock(buildKey(key));
	}

	public boolean lockHashRateOrder(@NotNull String key) {
		return this.lock(RedisLockConstant.ORDER + RedisLockConstant.ORDER_HASH_COMBO + key);
	}

	public void unlockHashRateOrder(@NotNull String key) {
		this.unlock(RedisLockConstant.ORDER + RedisLockConstant.ORDER_HASH_COMBO + key);
	}

	public static String buildKey(String hrOrderNo) {
		return RedisLockConstant.ORDER + RedisLockConstant.ORDER_HASH_COMBO + hrOrderNo;
	}

	public static String buildOrderKey(String hrOrderNo) {
		return RedisLockConstant.ORDER + RedisLockConstant.ORDER_HASH_COMBO + hrOrderNo;
	}
}
